#pragma once
#include "SehnsuchtPrecompiled.hxx"

namespace Sehnsucht
{
	ref_class_decl RenderTargetBase
	{
#if _Reign_desktop_support_windows_7
		typedef ID3D11DeviceContext *Context3Ptr;
#else
		typedef ID3D11DeviceContext1 *Context3Ptr;
#endif

	protected_owned_access:

		Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_d3dRenderTargetView;
		Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_d3dDepthStencilView;
		D3D11_VIEWPORT m_viewport;
		Reign::Color m_clear;

	public_owned_access:

		_Decl_value_prop_hinl2(m_clear, Reign::Color, Clear);
		REIGN_HINTINLINING void Clear(_In_ Context3Ptr d3dContext)
		{
			d3dContext->ClearRenderTargetView(
				m_d3dRenderTargetView.Get(),
				m_clear
				);
			d3dContext->ClearDepthStencilView(
				m_d3dDepthStencilView.Get(),
				D3D11_CLEAR_DEPTH,
				1.0f, 0ui8
				);
		}

		REIGN_FORCEINLINING void BindToPipeline(_In_ Context3Ptr d3dContext)
		{
			d3dContext->OMSetRenderTargets(1, m_d3dRenderTargetView.GetAddressOf(), m_d3dDepthStencilView.Get());
			d3dContext->RSSetViewports(1, &m_viewport);
		}

		REIGN_FORCEINLINING void UnbindFromPipeline(_In_ Context3Ptr d3dContext)
		{
			static ID3D11RenderTargetView *s_null_rtv = nullptr;
			static ID3D11DepthStencilView *s_null_dsv = nullptr;
			d3dContext->OMSetRenderTargets(0, &s_null_rtv, s_null_dsv);
		}
	};
};